@extends('layouts.base')



@section('content')

			<input type="hidden" id="_token" name="_token" value="{{ csrf_token() }}">
		    <div class="layui-card-body">
                <div id="node-list" class="demo-tree"></div>
                <hr class="layui-bg-gray">
                <button class="layui-btn" id="save">保存</button>
            </div>

@endsection

@section('script')

	<script type="text/javascript">
		var role_id = {{ $roleId }}, _token = $('#_token').val();

	    layui.use('tree', function() {
	        tree = layui.tree,
	        layer = layui.layer,
	        data =  @json($nodeList),
	        checked = @json($checked),
	        //基本演示
	        tree.render({
	            elem: '#node-list'
	            ,data: data
	            ,id: 'demoId'
	            ,showCheckbox: true
	        });
	        tree.setChecked('demoId', checked);

	        
	        $('#save').click(function() {
	            var checkedsObj = tree.getChecked('demoId'); //获得被勾选的节点
	            $.post('{{ url("admin/roles/auth_save") }}', {checked: checkedsObj, role_id: role_id, _token: _token}, function(result){
	                if (result.code == 0) {
	                    layer.msg(result.msg, {icon: 1, time: 2000})
	                }
	            })
	        })

	    })
	</script>

@endsection